/*
 * Duplicate Detector Copyright (C) 2010 Marco Biscaro <marcobiscaro2112@gmail.com>
 * 
 * This file is part of Duplicate Detector.
 *
 * Duplicate Detector is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Duplicate Detector is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Duplicate Detector.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.duplicatedetector.view;

import static com.googlecode.duplicatedetector.i18n.Messages._;

import javax.swing.JFrame;
import javax.swing.JMenuBar;

import com.googlecode.duplicatedetector.Constants;
import com.googlecode.duplicatedetector.i18n.Keys;
import com.googlecode.duplicatedetector.properties.PropertiesManager;
import com.googlecode.duplicatedetector.util.Logger;

/**
 * The main window.
 * 
 * @author Marco Biscaro
 */
public class MainFrame extends JFrame implements Keys, Constants {

	private static final long serialVersionUID = 7125973426577317656L;
	private static final Logger LOGGER = new Logger(MainFrame.class);

	public MainFrame() {
		initialize();
	}

	private void initialize() {
		MainPanel mainPanel = new MainPanel();
		JMenuBar menuBar = new MainMenuBar(mainPanel);
		setContentPane(mainPanel);
		setJMenuBar(menuBar);
		pack();
		setMinimumSize(getSize());
		setTitle(_(Keys.APP_NAME) + " " + APP_VERSION);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setLocationRelativeTo(null);
	}

	@Override
	public void dispose() {
		LOGGER.info("Writing properties file");
		PropertiesManager.write();
		LOGGER.info("Disposing window");
		super.dispose();
		// LOGGER.debug("Will shutdown JVM in 3 seconds");
		// new Thread(new ShutdownJVM()).start();
	}

	// private static class ShutdownJVM implements Runnable {
	//
	// @Override
	// public void run() {
	// try {
	// Thread.sleep(3000);
	// } catch (InterruptedException e) {
	// }
	// LOGGER.info("Goodbye!");
	// System.exit(0);
	// }
	//
	// }

}
